package com.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dao.ModuleDao;
import com.pojo.Module;
import com.util.ValidateHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ModuleService extends ServiceImpl<ModuleDao, Module> {

    @Autowired
    private ModuleDao moduleDao;

    /**
     * 分页查询模块信息
     * @param page
     * @param limit
     * @param name 子模块名称
     * @param status 状态：0禁用、1启用
     * @return
     */
    public IPage selectModulePage (Integer page, Integer limit, String name, Integer status,String type) {
        Page p = new Page(page, limit);
        QueryWrapper<Module> query = new QueryWrapper<>();
        if (ValidateHelper.isNotEmptyString(name)) {
            query.like("name", name);
        }
        if (ValidateHelper.isNotEmptyString(type)) {
            query.eq("parentName", type);
        }
        if (null != status) {
            query.eq("status", status);
        }
        IPage<Module> iPage = moduleDao.selectPage(p, query);
        return iPage;
    }

    /**
     * 根据父级菜单查询下面的模块列表
     * @return
     */
    public List<Module> getModuleListByParentName (String parentName) {
        QueryWrapper query = new QueryWrapper();
        query.eq("parentName", parentName);
        query.eq("isShowApp", 1);
        return moduleDao.selectList(query);
    }
}
